﻿namespace STT
{
    using System.Collections.Generic;
    using System.Windows.Forms;

    public class TableInfo : ListView
    {
        private ColumnHeader column_Valeur;
        private ColumnHeader column_Membre;

        public TableInfo()
        {
            this.Init(null);
        }

        public TableInfo(Control control_parent)
        {
            this.Init(control_parent);
        }

        public void DisplayInfo(List<string[]> list)
        {
            if (base.FindForm().InvokeRequired)
            {
                object[] args = new object[] { list };
                base.FindForm().Invoke(new f_list(this.DisplayInfo), args);
            }
            else
            {
                base.Items.Clear();
                if (list != null)
                {
                    foreach (string[] strArray in list)
                    {
                        base.Items.Add(new ListViewItem(strArray));
                    }
                }
            }
        }

        private void Init(Control control_parent)
        {
            base.SuspendLayout();
            this.column_Membre = new ColumnHeader();
            this.column_Membre.Text = "成员";
            this.column_Membre.Width = 200;
            this.column_Valeur = new ColumnHeader();
            this.column_Valeur.Text = "值";
            this.column_Valeur.Width = 200;
            ColumnHeader[] values = new ColumnHeader[] { this.column_Membre, this.column_Valeur };
            base.Columns.AddRange(values);
            base.View = View.Details;
            if (control_parent != null)
            {
                this.PlaceTo(control_parent);
            }
            base.ResumeLayout(false);
        }

        public void PlaceTo(Control control)
        {
            control.Controls.Add(this);
            this.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.Dock = DockStyle.Fill;
        }

        private delegate void f_list(List<string[]> list);
    }
}